package org.anyline.simple.office.controller;

import org.anyline.entity.DataRow;
import org.anyline.entity.DataSet;
import org.anyline.util.BasicUtil;
import org.anyline.web.util.WebUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("web.home.DocController")
@RequestMapping("/doc")
public class DocController extends BasicController {
    protected String dir = "doc";
    @RequestMapping("edit")
    public ModelAndView edit(HttpServletRequest request, HttpServletResponse response) {

        ModelAndView mv = template("edit.jsp");

        return mv;
    }
    @RequestMapping("print")
    public ModelAndView print(HttpServletRequest request, HttpServletResponse response) {

        ModelAndView mv = template("print.jsp");

        return mv;
    }
    @RequestMapping("cbk")
    @ResponseBody
    public String callback(HttpServletRequest request, HttpServletResponse response) {
        DataRow param = DataRow.parseJson(WebUtil.read(request, "UTF-8"));
        int status = 0;
        String cache_url = null;
        System.out.print("param:"+param);
        if(null != param){
            status = param.getInt("status",0);
            cache_url = param.getString("url"); //编辑后文件地址 //http://onlyoffice服务地址/cache/files/data/13be3b24761275750c95_6269/output.docx/output.docx?md5=Mb91G18BYA8-ciPyjqrmiA&expires=1694653054&filename=output.docx
        }

        if(status==2 || status== 3){
            if(BasicUtil.isNotEmpty(cache_url)){
                //HttpUtil.stream(cache_url).getInputStream()
            }
        }
        return "{\"error\":0}";
    }
}
